package huawei;

/**
 * 找终点
 */
public class FindEends {

    public static void main(String[] args) {
        int[] ints = {7,5,9,4,2,6,8,3,5,4,3,9};

        int min = Integer.MAX_VALUE;
        for (int step = 0; step < ints.length / 2; step++) {
            int i = step;
            int count = 1;
            while (i < ints.length) {
                if (i == ints.length - 1) {
                    min = Math.min(count, min);
                }

                count += 1;
                i += ints[i];
            }
        }
        if (min == Integer.MAX_VALUE) {
            System.out.println(-1);
        } else {
            System.out.println(min);
        }
    }
}


